package com.cskaoyan.service.wxuser;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cskaoyan.bean.po.wx_user.WxIssueListPO;
import com.cskaoyan.bean.vo.wxuser.WxIssueListVO;
import com.cskaoyan.mapper.wx_user.WxIssueListMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @Author: 冯子靖
 * @Description:
 * @Date: 2022/7/22 11:17
 */
@Data
@Service
public class WxIssueServiceImpl implements WxIssueService {

    private Integer limit;

    private Integer page;

    private Integer pages;

    private Integer total;

    private List<WxIssueListPO> list;

    @Autowired
    WxIssueListMapper wxIssueListMapper;
    @Override
    public WxIssueListVO printIssueList(Integer page, Integer limit) {
        this.page = page;
        this.limit = limit;

        PageHelper.startPage(page, limit);
        QueryWrapper<WxIssueListPO> wxIssueListPOQueryWrapper = new QueryWrapper<>();
        wxIssueListPOQueryWrapper.eq("deleted", 0);
        list= wxIssueListMapper.selectList(wxIssueListPOQueryWrapper);
        PageInfo<WxIssueListPO> wxIssueListPOPageInfo = new PageInfo<>(list);
        total = (int) wxIssueListPOPageInfo.getTotal();
        pages = wxIssueListPOPageInfo.getPages();

        WxIssueListVO wxIssueListVO = new WxIssueListVO();

        try {
            BeanUtils.copyProperties(wxIssueListVO, this);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return wxIssueListVO;

    }
}
